<?php
namespace app\admin\controller;
use think\facade\Db;
use app\admin\model\RegionModel;
use PhpOffice\PhpSpreadsheet\IOFactory;

class BandRoad  {
    public function importJson() {
        $data = json_decode($_POST['data'],true);
        var_dump($data);
        foreach($data as $value) {
            $value1 = array(
                'index_id'=>9,
                'value'=>$value['exportsAndimports'],
                'type'=>3,
                'date'=>$value['date']
            );
            $value2 = array(
                'index_id'=>8,
                'value'=>$value['exports'],
                'type'=>3,
                'date'=>$value['date']
            );
            $value3 = array(
                'index_id'=>10,
                'value'=>$value['imports'],
                'type'=>3,
                'date'=>$value['date']
            );

            Db::table('yhq_ydyl_index_data')->insert($value1);
            Db::table('yhq_ydyl_index_data')->insert($value2);
            Db::table('yhq_ydyl_index_data')->insert($value3);
        }
    }

    public function getIndexData() {
        $data = Db::table('yhq_ydyl_index_data')->field('a.*,d.id as did,d.index_name,d.index_code')->alias('a')->join(['yhq_ydyl_index'=>'d'],'a.index_id=d.id')->select();
        return array('data'=>$data);
    }

    public function ab() {
        // $json_string = file_get_contents(public_path().'static/48000-48053.json');
        // $data = json_decode($json_string,true);  
        // print_r($data[0]);
        // // $i=0;
        // // foreach($data as $key=>$value) {
        // //     $i++;
        // //     $params = array(
        // //         'fid'=>$value['properties']['FID'],
        // //         'region_code'=>$value['properties']['code'],
        // //         'geo_json'=>json_encode($value)
        // //     );
        // //     Db::table('yhq_town_geo_json')->insert($params);
        // // }
        // // echo $i;
        // $list = Db::table('yhq_town_geo_json')->page(10,5000)->select();
        // $i=0;
        // foreach($list as $value) {
        //     $i++;
        //     $data = json_decode($value['geo_json'],true);
        //     $params = array('region_name'=>$data['properties']['Name']);
        //     $result = Db::table('yhq_town_geo_json')->where('id',$value['id'])->update($params);
        // }
        // echo $i;
    }
}